package webv1

import (
	"github.com/gin-gonic/gin"
	"myCloud/dbopr"
	"net/http"
)

func serverInfoApiInit(r *gin.RouterGroup) {
	g := r.Group("/server")

	// 服务器基本信息，版本匹配度？
	g.GET("/info", serverInfoHandler)
}

type serverInfoResponse struct {
	Name     string `json:"name"`
	Version string `json:"version"`
	ServerID string `json:"server_id"`
}

func serverInfoHandler(c *gin.Context) {
	p := dbopr.NewServerProvider()
	rsp, err := p.Get()
	if err != nil {
		abReq(c, http.StatusInternalServerError, "获取服务器信息失败", err)
	}

	var out = &serverInfoResponse{
		Name:     rsp.Name,
		ServerID: rsp.ServerID,
	}
	c.JSON(http.StatusOK, out)
}

